package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.FdsBusinessClosingRulesetMapper;
import com.yunhai.device.service.FdsBusinessClosingRulesetService;
import com.yunhai.model.entity.fds.FdsBusinessClosingRulesetEntity;
import com.yunhai.model.vo.fds.FdsBusinessClosingRulesetQuery;
import com.yunhai.model.vo.fds.FdsBusinessClosingRulesetVo;
import org.apache.commons.beanutils.PropertyUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FdsBusinessClosingRulesetServiceImpl implements FdsBusinessClosingRulesetService {

    @Resource
    private FdsBusinessClosingRulesetMapper fdsBusinessClosingRulesetMapper;

    /**
     * 获取 FdsBusinessClosingRuleset 分页列表
     */
    @Transactional
    public IPage getFdsBusinessClosingRulesetPagination(PaginationVo paginationVo, FdsBusinessClosingRulesetQuery fdsBusinessClosingRulesetQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<FdsBusinessClosingRulesetEntity> lqs = new LambdaQueryWrapper();
        fdsBusinessClosingRulesetMapper.selectPage(page, lqs);

        List<FdsBusinessClosingRulesetEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return page;
    }


    /**
     * 获取 FdsBusinessClosingRuleset 所有数据
     *
     */
    @Transactional
    public List<FdsBusinessClosingRulesetEntity> getFdsBusinessClosingRulesetAllList( FdsBusinessClosingRulesetQuery fdsBusinessClosingRulesetQuery ) throws Exception {

        LambdaQueryWrapper<FdsBusinessClosingRulesetEntity> lqs = new LambdaQueryWrapper();
        List<FdsBusinessClosingRulesetEntity> list = fdsBusinessClosingRulesetMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 FdsBusinessClosingRuleset 详情
     */
    @Transactional
    public FdsBusinessClosingRulesetEntity getFdsBusinessClosingRulesetDetail( Long id) throws Exception {

        FdsBusinessClosingRulesetEntity fdsBusinessClosingRulesetEntity = fdsBusinessClosingRulesetMapper.selectById(id);
        return fdsBusinessClosingRulesetEntity;
    }


    /**
     * 新增 FdsBusinessClosingRuleset
     * */
    @Transactional
    public void addFdsBusinessClosingRuleset(FdsBusinessClosingRulesetVo fdsBusinessClosingRulesetVo) throws Exception {

        FdsBusinessClosingRulesetEntity fdsBusinessClosingRulesetEntity = new FdsBusinessClosingRulesetEntity();
        ReflectionCopy.copyProperties( fdsBusinessClosingRulesetEntity, fdsBusinessClosingRulesetVo );
        fdsBusinessClosingRulesetMapper.insert(fdsBusinessClosingRulesetEntity);
        return;
    }


    /**
     * 更新 FdsBusinessClosingRuleset
     * */
    @Transactional
    public void updateFdsBusinessClosingRuleset( FdsBusinessClosingRulesetVo fdsBusinessClosingRulesetVo) throws Exception {

        if( fdsBusinessClosingRulesetVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        FdsBusinessClosingRulesetEntity fdsBusinessClosingRulesetEntity = new FdsBusinessClosingRulesetEntity();
        ReflectionCopy.copyProperties( fdsBusinessClosingRulesetEntity, fdsBusinessClosingRulesetVo );
        fdsBusinessClosingRulesetMapper.updateById(fdsBusinessClosingRulesetEntity);
        return;
    }

    /**
     * 删除 FdsBusinessClosingRuleset
     * */
    @Transactional
    public void batchRemoveFdsBusinessClosingRuleset( List<Long> ids ) throws Exception {

        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        fdsBusinessClosingRulesetMapper.deleteBatchIds(ids);
    }

}